import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { TemplateService } from './template.service';
import { CreateTemplateDto } from './dto/create-template.dto';
import { UpdateTemplateDto } from './dto/update-template.dto';
import { QueryDto } from './dto/query.dto';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
import { MessagePattern, Payload } from '@nestjs/microservices';

@Controller('template')
export class TemplateController {
  constructor(private readonly templateService: TemplateService) {}

  @Post()
  @ApiOperation({
    summary: '创建template',
    description: '创建template',
  })
  @ApiResponse({
    status: 200,
    description: '创建成功',
    type: CreateTemplateDto,
  })
  @MessagePattern('createTemplate')
  create(createTemplateDto: CreateTemplateDto) {
    return this.templateService.create(createTemplateDto);
  }

  @Get()
  @ApiOperation({
    summary: '获取template列表',
    description: '获取template列表',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: [UpdateTemplateDto],
  })
  @MessagePattern('findAllTemplate')
  findAll(query: QueryDto) {
    return this.templateService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({
    summary: '获取template详情',
    description: '获取template详情',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: UpdateTemplateDto,
  })
  @MessagePattern('findOneTemplate')
  findOne(id: string) {
    return this.templateService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({
    summary: '更新template',
    description: '更新template',
  })
  @ApiResponse({
    status: 200,
    description: '更新成功',
    type: UpdateTemplateDto,
  })
  @MessagePattern('updateTemplate')
  update(@Payload('id') id: string, @Payload('updateKitDto') updateKitDto: UpdateTemplateDto) {
    return this.templateService.update(+id, updateKitDto);
  }

  @Delete(':id')
  @ApiOperation({
    summary: '删除kit',
    description: '删除kit',
  })
  @ApiResponse({
    status: 200,
    description: '删除成功',
    type: UpdateTemplateDto,
  })
  @MessagePattern('removeKit')
  remove(id: string) {
    return this.templateService.remove(+id);
  }
}
